/**
 * 
 */
package net.it2pro.communication;

import org.apache.log4j.Logger;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;

/**
 * @author nttuyen
 *
 */
public class GoogleChatter extends AbstractChatter implements MessageListener {
	private final Logger log = Logger.getLogger(GoogleChatter.class);
	
	private final Chat chat;
	
	public GoogleChatter(Chat chat) {
		this.chat = chat;
	}
	
	public void reply(String from, String message) {
		try {
			this.chat.sendMessage("[" + from + "]" + message);
		} catch (XMPPException e) {
			this.log.error("Send message exception", e);
		}
	}

	public void processMessage(Chat from, Message message) {
		this.log.debug("Receive message from [" + from.getParticipant() + "]: " + message.getBody());
		this.receive(from.getParticipant(), message.getBody());
	}

	public String getIdentify() {
		return this.chat.getParticipant();
	}
}
